import type { PageParam, PageResult } from '@vben/request';
import { requestClient } from '#/api/request';

export namespace PhotographerApi {
  /** 摄影师资源信息 */
  export interface Photographer {
    id: number;
    photographerCode?: string;
    photographerName?: string;
    level: string;
    specialtyStyle: string;
    servicePrice: number;
    rating: number;
    shootingCount: number;
    status: string;
    remark: string;
    avatar?: string;
    gender?: string;
    phone?: string;
    serviceLevel?: string;
    workYears?: number;
    specialtyStyles?: string[];
    equipment?: string[];
    introduction?: string;
    portfolio?: string[];
  }

  /** 摄影订单 */
  export interface PhotographyOrder {
    id: number;
    orderId: string;
    photographerCode: string;
    photographerName: string;
    customerId: string;
    customerName: string;
    shootingTime: string;
    shootingLocation: string;
    photoCount: number;
    retouchCount: number;
    serviceAmount: number;
    paidAmount: number;
    status: string;
    deliveryTime?: string;
    createTime: string;
  }

  /** 作品集项 */
  export interface PortfolioItem {
    id: number;
    title: string;
    style: string;
    images: string[];
    description: string;
    createTime: string;
  }
}

// ==================== 标准CRUD接口 (/wedding/photographer) ====================

/** 查询摄影师资源分页 */
export function getPhotographerPage(params: PageParam) {
  return requestClient.get<PageResult<PhotographerApi.Photographer>>('/wedding/photographer/page', { params });
}

/** 查询摄影师资源详情 */
export function getPhotographer(id: number) {
  return requestClient.get<PhotographerApi.Photographer>(`/wedding/photographer/get?id=${id}`);
}

/** 新增摄影师资源 */
export function createPhotographer(data: PhotographerApi.Photographer) {
  return requestClient.post('/wedding/photographer/create', data);
}

/** 修改摄影师资源 */
export function updatePhotographer(data: PhotographerApi.Photographer) {
  return requestClient.put('/wedding/photographer/update', data);
}

/** 删除摄影师资源 */
export function deletePhotographer(id: number) {
  return requestClient.delete(`/wedding/photographer/delete?id=${id}`);
}

/** 导出摄影师资源 */
export function exportPhotographer(params: any) {
  return requestClient.download('/wedding/photographer/export-excel', { params });
}

// ==================== 扩展功能接口 (/wedding/resource/photographer) ====================

const resourceBaseUrl = '/wedding/resource/photographer';

/** 获取摄影师拍摄订单 */
export function getPhotographyOrders(photographerCode: string) {
  return requestClient.get<PhotographerApi.PhotographyOrder[]>(
    `${resourceBaseUrl}/orders`,
    { params: { photographerCode } },
  );
}

/** 获取摄影师统计数据 */
export function getPhotographerStatistics(photographerCode: string) {
  return requestClient.get<{
    totalOrders: number;
    completedOrders: number;
    averageRating: number;
    totalRevenue: number;
  }>(`${resourceBaseUrl}/statistics`, {
    params: { photographerCode },
  });
}

/** 获取摄影师作品集 */
export function getPhotographerPortfolio(photographerCode: string, params?: {
  style?: string;
  pageNo?: number;
  pageSize?: number;
}) {
  return requestClient.get<PageResult<PhotographerApi.PortfolioItem>>(
    `${resourceBaseUrl}/portfolio`,
    { params: { photographerCode, ...params } },
  );
}

/** 上传摄影师头像 */
export function uploadPhotographerAvatar(file: File) {
  const formData = new FormData();
  formData.append('file', file);
  return requestClient.post<string>(
    `${resourceBaseUrl}/upload-avatar`,
    formData,
    {
      headers: {
        'Content-Type': 'multipart/form-data',
      },
    },
  );
}

/** 上传作品集图片 */
export function uploadPortfolioImage(file: File) {
  const formData = new FormData();
  formData.append('file', file);
  return requestClient.post<string>(
    `${resourceBaseUrl}/upload-portfolio`,
    formData,
    {
      headers: {
        'Content-Type': 'multipart/form-data',
      },
    },
  );
}
